package com.roc.web.action;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.roc.page.BaseSearchCondition;
import com.roc.page.PaginationBaseAction;
import com.roc.pojo.PayBank;
import com.roc.service.IPagenitionService;
import com.roc.service.ServiceException;
import com.roc.util.Constance;
@Component
@Scope("prototype")
@Namespace("/bankinfo")
public class BankInfoAction extends PaginationBaseAction{

	private Logger logger=LogManager.getLogger(BankInfoAction.class);
	private BankInfoSearchCondition searchCondition;
	private PayBank bankInfo;
	
	@Autowired
	IPagenitionService pagenitionService;
	
	@Action(value = "init", results = { @Result(name = "success", location = "/pages/bankinfo/bankinfo_query.jsp")
    })
	public String init(){
		return SUCCESS;
	}
	
	@Action(value = "queryBankInfo", results = { @Result(name = "success", location = "/pages/bankinfo/bankinfo_query.jsp"),
			@Result(name = "error", location = "/error.jsp")
    })
	public String queryBankInfo(){
	
		if(searchCondition==null){
			searchCondition=(BankInfoSearchCondition)getSearchConditionFromSession();
			if(searchCondition==null){
				searchCondition=new BankInfoSearchCondition();
			}
		}
		try {
			init(); 
			
			int rows=pagenitionService.count(searchCondition);
			if(rows>0){
				searchRsList=pagenitionService.findAll(searchCondition, calcuStart(getCurrentPage()), Constance.PAGE_MAX_SIZE);

			}
			//dealWithTheListSpecially(searchRsList);
			this.setTotalPage(this.calcuTotalPage(rows));
			getRequest().setAttribute(SEARCH_RS_LIST, searchRsList);
			getRequest().setAttribute(CURRENT_PAGE, this.getCurrentPage());
			getRequest().setAttribute(TOTAOL_PAGE, this.getTotalPage());
			setSearchToConditionSession(searchCondition);
			
		} catch (ServiceException e) {
			
			logger.error(e.getMessage(),e);
			addActionError(e.getMessage());
			
		}
		
		
		return SUCCESS;
	}
	
	@Override
	protected BaseSearchCondition getSearchConditionFromSubClass()
			throws Exception {
		// TODO Auto-generated method stub
		return searchCondition;
	}

	@Override
	protected void setSearchConditionToSubClass(
			BaseSearchCondition searchCondition) throws Exception {
		// TODO Auto-generated method stub
		this.setSearchConditionToSubClass(searchCondition);
	}

	@Override
	protected void setSearchToConditionSession(
			BaseSearchCondition searchCondition) {
		// TODO Auto-generated method stub
		getSession().setAttribute(SEARCH_SESSION_BEAN_BANKINFO_QUERY, searchCondition);
	}

	@Override
	protected BaseSearchCondition getSearchConditionFromSession() {
		// TODO Auto-generated method stub
		return (BaseSearchCondition) getSession().getAttribute(SEARCH_SESSION_BEAN_BANKINFO_QUERY);
	}

	@Override
	protected String getInitPageSize() {
		// TODO Auto-generated method stub
		return Constance.PAGE_MAX_SIZE+"";
	}

	public BankInfoSearchCondition getSearchCondition() {
		return searchCondition;
	}

	public void setSearchCondition(BankInfoSearchCondition searchCondition) {
		this.searchCondition = searchCondition;
	}

	public PayBank getBankInfo() {
		return bankInfo;
	}

	public void setBankInfo(PayBank bankInfo) {
		this.bankInfo = bankInfo;
	}

	
	
	

}
